package com.syb.controller.function;

import java.util.List;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.syb.entity.function.SysRole;
import com.syb.service.RoleService;
import com.syb.util.PageResults;

@SuppressWarnings("serial")
@Namespace("/role")
public class RoleController extends ActionSupport{
	
	private static  Logger logger  = Logger.getLogger(LoginController.class);
	
	@Autowired
	private RoleService roleService;
	
	private Integer currentPage;
	
	private String name;

	@Action(value="getRoleList",
			results={
			@Result(name="success",location="/jsp/background/role/list.jsp"),
			@Result(name="error",location="/error.jsp")
			})
	public String  getSysRoleList(){
		PageResults<SysRole>  page = new PageResults<SysRole>();
		//组装参数
		if(name!=null&&name.length()>0){
			page.getParamMap().put("name", name);
		}
		if(currentPage!=null&&!currentPage.equals("")){
			page.setCurrentPage(currentPage);
		}
		PageResults<SysRole> sysRoleList = new PageResults<SysRole>();
		try{
			sysRoleList=roleService.findSysRoleList(page);
		}catch(Exception e){
			logger.error(e.getMessage());
			ActionContext.getContext().put("error", e.getMessage());
		}
		ActionContext.getContext().put("result", sysRoleList);
		return "success";
	}
	

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}


	public int getCurrentPage() {
		return currentPage;
	}


	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}
	
	
	
}
